home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Archive / Graphics / QuickDraw GX / IW-Half-Dither / source / ChooserSupportLDEF.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  6.2 KB  |  223 lines  |  [TEXT/MPS ]

  1. /*
  2.     ChooserSupport.c - C code for PACK and LDEF resources used by the Chooser.
  3.     
  4.     Copyright © 1992-1994 Apple Computer, Inc.
  5.     All rights reserved.
  6.  
  7.     12/20/93        dmh                Sync'd with the shipping 1.0b3 GX driver.
  8.      8/26/94        dmh                Sync'd with the shipping 1.0.1 GX driver.
  9.      8/26/94        dmh                Universalized code.
  10. */
  11.  
  12. #include <Types.h>
  13. #include <QuickDraw.h>
  14. #include <Fonts.h>
  15. #include <Lists.h>
  16. #include <Devices.h>
  17. #include <Resources.h>
  18. #include <Script.h>
  19. #include <ToolUtils.h>
  20. #include <LowMem.h>
  21.  
  22. #ifndef __GXGRAPHICS__
  23.     #include <GXGraphics.h>
  24. #endif
  25. #ifndef __GXPRINTERDRIVERS__
  26.     #include <GXPrinterDrivers.h>
  27. #endif
  28.  
  29. #include "ChooserSupportProtos.h"
  30.  
  31.  
  32. // ------------------------------------------------------------------------
  33. // INTERNAL DEFINES
  34. // ------------------------------------------------------------------------
  35. // Chooser initialize message selector
  36. #define initializeMsg    11
  37.  
  38. // Icon Suite support
  39. #define ttNone        0x0000
  40. #define ttDisabled    0x0001
  41. #define    ttOffline    0x0002
  42. #define ttOpen        0x0003
  43. #define ttSelected     0x4000
  44. #define ttSelectedDisabled    (ttSelected + ttDisabled)
  45. #define ttSelectedOffline    (ttSelected + ttOffline)
  46. #define ttSelectedOpen        (ttSelected + ttOpen)
  47.  
  48. #define ttLabel0    0x0000
  49. #define ttLabel1    0x0100
  50. #define ttLabel2    0x0200
  51. #define ttLabel3    0x0300
  52. #define ttLabel4    0x0400
  53. #define ttLabel5    0x0500
  54. #define ttLabel6    0x0600
  55. #define ttLabel7    0x0700
  56.  
  57. // Copy of the DrawText trap
  58. pascal void OldDrawText(const void *textBuf,short firstByte,short byteCount)
  59.     = 0xA885; 
  60.  
  61.  
  62. // ------------------------------------------------------------------------
  63. // ENTRY POINT FOR LDEF
  64. // ------------------------------------------------------------------------
  65.  
  66. pascal void main(
  67.     short         message,        // What operation to perform on list
  68.     Boolean     select,            // Is this cell to be selected or not?
  69.     Rect        *theRect,        // Rectangle of this cell, clipped to window
  70.     Cell        theCell,        // Which cell this is
  71.     short        dataOffset,        // Offset into data for this cell
  72.     short        dataLen,        // Length of data for this cell
  73.     ListHandle    theList)        // The list to act upon
  74. /*
  75.     An LDEF that works in two modes:
  76.         - if the first two characters of the cell are valid AppleTalk NBP names (ie, not ≈ ≈)
  77.           then the LDEF is just a basic text LDEF
  78.         - otherwise, it assumes the data is part of a PortListRec, which is
  79.           a structure for icons with text underneath
  80. */
  81.  
  82. {
  83.  
  84.     gxPortListRec        theCellContents;
  85.     Rect                iconRect;
  86.     unsigned char        hiliteMode;
  87.     
  88.     switch (message)
  89.         {
  90.         case lDrawMsg:
  91.         case lHiliteMsg:
  92.         
  93.             // save the data to avoid locking things down
  94.             if (dataLen > sizeof(theCellContents) )
  95.                 dataLen = sizeof(theCellContents);
  96.             BlockMove(((*(**theList).cells) + dataOffset), &theCellContents, dataLen );
  97.             
  98.             // draw the cell as an icon, but only if we see our magic marker at the front
  99.             if ( (theCellContents.firstMarker == '≈') && (theCellContents.secondMarker == '≈') )
  100.                 {
  101.                 // center the icon rect on the list with a top margin of 10 pixels
  102.                 iconRect.top = theRect->top + 10;
  103.                 iconRect.left = theRect->left + ((theRect->right - theRect->left) >> 1) - 16;
  104.                 iconRect.bottom = iconRect.top + 32;
  105.                 iconRect.right = iconRect.left + 32;
  106.                 
  107.                 
  108.                 // draw the icon
  109.                 if (theCellContents.iconSuiteHandle != nil)
  110.                     PlotIconSuite(&iconRect,
  111.                             ttNone, (select) ? ttSelected: ttNone,
  112.                             theCellContents.iconSuiteHandle);
  113.                             
  114.                 // Get the general area under the icon in which to draw the label
  115.                 iconRect.left = theRect->left + 2;
  116.                 iconRect.right = iconRect.left + (**theList).cellSize.h - 2;
  117.                 iconRect.top = iconRect.bottom + 2;
  118.                 iconRect.bottom = theRect->bottom;
  119.     
  120.                 // use a nice small font for the label            
  121.                 TextFont(applFont);
  122.                 TextSize(9);
  123.                 
  124.                     {
  125.                     short        labelWidth;
  126.                     short        rectWidth;
  127.                     short        labelHeight;
  128.                     FontInfo    theInfo;
  129.                 
  130.                     // Get rid of any text that was there before
  131.                     EraseRect(&iconRect);
  132.                     iconRect.top += 2;
  133.                     
  134.                     // compute the height of the label                    
  135.                     GetFontInfo(&theInfo);
  136.                     labelHeight = theInfo.ascent + theInfo.leading;
  137.                     
  138.                     // compute where to draw the text
  139.                     iconRect.bottom = iconRect.top + labelHeight;
  140.                     rectWidth = iconRect.right-iconRect.left;
  141.                     
  142.                     // truncate the string to fit within the box
  143.                     TruncString(rectWidth, theCellContents.iconName, smTruncEnd);
  144.                     
  145.                     // compute the new width of the string
  146.                     labelWidth = StringWidth(theCellContents.iconName);
  147.                     
  148.                     // center the string, draw it
  149.                     iconRect.left += (rectWidth >> 1) - (labelWidth >> 1);
  150.                     MoveTo(iconRect.left, iconRect.bottom);
  151.                     DrawString(theCellContents.iconName);
  152.                     
  153.                     if (select)
  154.                         {
  155.                         // compute right and lower edge of box bounding the text we just drew
  156.                         iconRect.right = iconRect.left + labelWidth;
  157.                         iconRect.bottom += theInfo.descent;
  158.                         
  159.                         // outset it, and invert it to select it
  160.                         InsetRect(&iconRect, -1, -1);
  161.                         hiliteMode = LMGetHiliteMode();
  162.                         BitClr(&hiliteMode, pHiliteBit);
  163.                         LMSetHiliteMode(hiliteMode);
  164.                         InvertRect(&iconRect);
  165.                         }
  166.                     }
  167.                     
  168.                 TextFont(applFont);
  169.                 TextSize(0);
  170.                 }
  171.             else
  172.                 {
  173.                 // how boring!  It's only text
  174.                 FontInfo    theInfo;
  175.                 Rect        ourRect;
  176.                 short        cellWidth;
  177.                 
  178.                 // add a margin to the rectangle
  179.                 ourRect = *theRect;
  180.                 ourRect.left += 4;
  181.                 --ourRect.right;
  182.                 cellWidth = ourRect.right - ourRect.left;
  183.                 
  184.                 // erase the rectangle
  185.                 GetFontInfo(&theInfo);
  186.                 EraseRect(theRect);
  187.                 MoveTo(ourRect.left, ourRect.bottom - theInfo.descent);
  188.                 
  189.                 // hey, you can't park that string here -- it's too big!
  190.                 if (TextWidth((Ptr) &theCellContents, 0, dataLen) > cellWidth )
  191.                     {
  192.                     // condense the text first
  193.                     TextFace(condense);
  194.                     
  195.                     // then truncate afterwards
  196.                     TruncText(cellWidth, (Ptr) &theCellContents, &dataLen, smTruncEnd);
  197.                     }
  198.                     
  199.                 // those darn other languages!
  200.                 if (GetSysJust() == teJustRight)
  201.                     Move(cellWidth-TextWidth((Ptr) &theCellContents, 0, dataLen) , 0);
  202.                     
  203.                 OldDrawText((Ptr) &theCellContents, 0, dataLen);
  204.                 
  205.                 // if selected, invert it
  206.                 if (select)
  207.                     {
  208.                     hiliteMode = LMGetHiliteMode();
  209.                     BitClr(&hiliteMode, pHiliteBit);
  210.                     LMSetHiliteMode(hiliteMode);
  211.                     InvertRect(theRect);
  212.                     }
  213.                     
  214.                 // normal text again
  215.                 TextFace(normal);
  216.                 }
  217.                 
  218.             break;
  219.             
  220.         } // switch
  221.         
  222. } // LDEF
  223.